// 取消页面默认滚动
$(window).mousewheel(function(event){
  	 event.stopPropagation();
	 event.preventDefault();
 	});

var scrollOver = 1; 
var scroll_obj = $(".con");//所有滚动模块
var windowH;
var conH = [0]; //n个区间 ,第一个为0；
$(window).resize(function(){
		windowH = $(window).height();
		init();
	})
windowH = $(window).height();
//初始化、重置页面模块高度
function init(){
	for(var i = 0; i<scroll_obj.length; i++){
		if(windowH < 700){
　				scroll_obj.eq(i).height(700);
			}else{
				if(i==0){
					scroll_obj.eq(i).height(windowH-44);
					}else{
						scroll_obj.eq(i).height(windowH);
					}
			 }
		if(i == 0){
			  conH[i + 1] = 44 + scroll_obj.eq(i).height();
			}else{
				conH[i + 1] = conH[i] + scroll_obj.eq(i).height();
				}
		
 		}
	}
//返回当前显示模块
function isArea (){
	var wh  = $(window).scrollTop();
	for(var i = 0; i < conH.length - 1; i++){
		if(wh >= conH[i] && wh < conH[i + 1]){
				return i;
			}
		if(wh > conH[conH.length - 1]){
				return i;
 			}
		}
		
	}
//上滚
function scrollUp(){
	//console.log("上滚");
	  scrollOver  = 0;
	  var con_index = isArea ();
	  if(con_index > 0){
			  $("body, html").animate({scrollTop:conH[con_index - 1]}, "slow", function(){
			   scrollOver  = 1;
			  });
		  }else{
 			 	 $("body, html").animate({scrollTop:conH[0]}, "slow", function(){
			  	 scrollOver  = 1;
			   });
 			  }	
	}
//下滚
function scrollDown(){
	 scrollOver = 0;
	 //console.log("下滚");
	 var bottomH = $("body, html").height() - $(window).height();
	  var con_index = isArea ();
	  if(scroll_obj.length - 1> con_index){
	  $("body, html").animate({scrollTop:conH[con_index + 1]}, "slow", function(){
		   scrollOver  = 1;
		  });
	 }else{
		  $("body, html").animate({scrollTop: bottomH + "px"}, "slow", function(){
		   scrollOver  = 1;
		  });
		 	
		 }
	}
//绑定判断上滚、下滚	
$("body").bind("mousewheel",function(event, delta, deltaX, deltaY) {
		var o = '';
		if (delta > 0){			
			if(scrollOver){
					o = '#test1: up ('+delta+')';
					scrollUp();
				}
			}
			
		else if (delta < 0)
			if(scrollOver){
					o = '#test1: down ('+delta+')';
					scrollDown();
				}
 			 
	});
init(); //初始化、重置页面模块高度